﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;
using DAL;
using Utility;

namespace BUS
{
    public class Tbl_CTDH_BUS
    {
        public static Tbl_CTDH_Collection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {
            Tbl_CTDH_DAL ctdhDAL = new Tbl_CTDH_DAL();
            return ctdhDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static Tbl_CTDH_Collection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            Tbl_CTDH_DAL ctdhDAL = new Tbl_CTDH_DAL();
            return ctdhDAL.Get(cri.Criter, 0, 0, Tbl_CTDH_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static Tbl_CTDH_Entities GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, Tbl_CTDH_Columns.STT.ToString(), Condition.EQUAL, iD);
            Tbl_CTDH_DAL ctdhDAL = new Tbl_CTDH_DAL();
            Tbl_CTDH_Collection ctdhCollection = ctdhDAL.Get(cri.Criter, 0, 0, Tbl_CTDH_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
            if (ctdhCollection.Count > 0)
                return ctdhCollection[0];
            return null;
        }
        public static Tbl_CTDH_Entities GetByIDDH(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, Tbl_CTDH_Columns.DonHang.ToString(), Condition.EQUAL, iD);
            Tbl_CTDH_DAL ctdhDAL = new Tbl_CTDH_DAL();
            Tbl_CTDH_Collection ctdhCollection = ctdhDAL.Get(cri.Criter, 0, 0, Tbl_CTDH_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
            if (ctdhCollection.Count > 0)
                return ctdhCollection[0];
            return null;
        }
        public static Tbl_CTDH_Entities GetByIDSP_1(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, Tbl_CTDH_Columns.SanPham.ToString(), Condition.EQUAL, iD);
            Tbl_CTDH_DAL ctdhDAL = new Tbl_CTDH_DAL();
            Tbl_CTDH_Collection ctdhCollection = ctdhDAL.Get(cri.Criter, 0, 0, Tbl_CTDH_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
            if (ctdhCollection.Count > 0)
                return ctdhCollection[0];
            return null;
        }
        public static Tbl_CTDH_Collection GetByIDSP(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, Tbl_CTDH_Columns.SanPham.ToString(), Condition.EQUAL, iD);
            Tbl_CTDH_DAL ctdhDAL = new Tbl_CTDH_DAL();
            return ctdhDAL.Get(cri.Criter, 0, 0, Tbl_CTDH_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static int CountByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, Tbl_CTDH_Columns.DonHang.ToString(), Condition.EQUAL, iD);
            Tbl_CTDH_DAL ctdhDAL = new Tbl_CTDH_DAL();
            Tbl_CTDH_Collection ctdhCollection = ctdhDAL.Get(cri.Criter, 0, 0, Tbl_CTDH_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
            return ctdhCollection.Count;
        }
        public static int CountByIDSP(int iD)
        {
            int total = 0;
            int sovcdadat = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, Tbl_CTDH_Columns.SanPham.ToString(), Condition.EQUAL, iD);
            Tbl_CTDH_DAL ctdhDAL = new Tbl_CTDH_DAL();
            Tbl_CTDH_Collection ctdhCollection = ctdhDAL.Get(cri.Criter, 0, 0, Tbl_CTDH_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
            if (ctdhCollection.Count > 0)
            {
                for (int i = 0; i < ctdhCollection.Count; i++)
                {
                    sovcdadat = sovcdadat + ctdhCollection[i].SoLuong;
                }
            }
            return sovcdadat;
        }
        public static void Insert(Tbl_CTDH_Entities ctdh)
        {
            Tbl_CTDH_DAL ctdhDAL = new Tbl_CTDH_DAL();
            ctdhDAL.Insert(ctdh);
        }
        public static void Update(Tbl_CTDH_Entities ctdh)
        {
            Tbl_CTDH_DAL ctdhDAL = new Tbl_CTDH_DAL();
            ctdhDAL.Update(ctdh);
        }
        public static void Delete(int id)
        {
            Tbl_CTDH_DAL ctdhDAL = new Tbl_CTDH_DAL();
            ctdhDAL.Delete(id);
        }
    }
}
